package com.qhhc.controller;

import com.qhhc.entity.Car;
import com.qhhc.service.ICarService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class CarController {
    @Autowired
    ICarService carService;

    @RequestMapping("/insertCar")
    public String insertCar(@RequestBody Car car){
        carService.insert(car);
        return "success";
    }
    
    @RequestMapping("/getAllCars")
    public List<Car> getAllCars(){
        List<Car> cars = carService.selectAll();
        for (Car car : cars) {
            System.out.println(car);
        }
        return cars;
    }
    
    @RequestMapping("/getCar/{id}")
    public Car getCarById(@PathVariable("id") Long id){
        return carService.selectById(id);
    }
    
    @RequestMapping("/updateCar")
    public String updateCar(@RequestBody Car car){
        carService.update(car);
        return "success";
    }
    
    @RequestMapping("/deleteCar/{id}")
    public String deleteCar(@PathVariable("id") Long id){
        carService.delete(id);
        return "success";
    }
}
